<!DOCTYPE html>
<html lang="en">
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/laypage.css">
    <link rel="stylesheet" href="/layui-util/css/layui.css" media="all">
    <script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
    <script type=text/javascript src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script src="/js/vue/vue.min.js"></script>
    <script src="/layui-util/layui.js" charset="utf-8"></script>
    <script src="/js/layer/layer.js" charset="utf-8"></script>
    <style>
        select.error, input.error {
            border: 1px solid red;
        }
    </style>
</head>
<body>
<section id="container">

    <section id="main-content">

        <div class="row">
            <div class="col-lg-12" id="app">
                <section class="panel" style=" width: 350px;margin: 0 auto">
                    <header class="panel-heading">
                        修改套餐
                    </header>
                    <div class="panel-body" >
                        <div class="form">
                            <form class="cmxform form-horizontal" id="updateComboForm">
                                <input type="hidden" value="${combo1.comuuid}" name="comuuid" id="comuuid">
                                <div class="form-group ">
                                    <label for="combname" class="control-label col-lg-3">套餐名称</label>
                                    <div class="col-lg-6">
                                        <input type="hiden" value="${combo1.combname}" id="combname" name="combname" >
                                    </div>
                                </div>

                                <div class="form-group ">
                                    <label for="maxinsur" class="control-label col-lg-3">套餐内容</label>
                                    <table style="margin-left: 20px">
                                            <#list combo1.list as str>
                                                <tr>
                                                    <td>${str.insurname}</td>
                                                </tr>
                                            </#list>
                                    </table>
                                </div>
                                <div class="form-group ">
                                    <label for="combrate" class="control-label col-lg-3">套餐优惠率</label>
                                    <div class="col-lg-6">
                                        <input type="hiden" value="${(combo1.combrate)?string("0.#")}" id="combrate" name="combrate" >
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-lg-offset-3 col-lg-6">
                                        <button class="btn btn-primary" type="button" id="referBut">提交</button>
                                        <button class="btn btn-primary" type="button" id="cancelBut">取消修改</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </section>
            </div>
        </div>
        </div>
    </section>
</section>
</section>

</body>
</html>
<script>
    var  updateCombo= function () {
        if (!check().form()) {
            return;
        }
        $.ajax({
            url: '/comb/updateCombo',
            type: 'post',
            data: $("#updateComboForm").serialize(),
            success: function (data) {
                if(data){
                    $("#cancelBut").click();
                    parent.layer.msg('修改成功', {icon: 6});
                }else {
                    layer.msg("参数异常,修改失败", {icon: 5});
                }
            }
        });
    };
    jQuery.validator.addMethod("regex", function (value, element, params) {
        var exp = new RegExp(params);
        return exp.test(value);
    }, "格式错误");
    var check =function () {
        return $("#updateComboForm").validate({
            rules: {
                combname: {
                    required: true,
                    rangelength: [3, 15]
                },
                combrate: {
                    required: true,
                    regex: "^0\\.[1-9]\\d*$"
                }
            },
            messages: {
                combname: {
                    required: "",
                    rangelength: "套餐名称长度在4-15之间"
                },
                combrate: {
                    required: "",
                    regex: "套餐赔率必须小于1,大于0"
                }
            }
        });
    };
    $("#referBut").click(function () {
        updateCombo();
    });
    $("#cancelBut").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getComboList();
        parent.layer.close(index);
    });
    $("#updateComboForm").mouseenter(function () {
        if (!check().form()) {
            return;
        }
    });
</script>